package com.wc.alorithm_blue_bridge._模拟.挑选武将;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/12/19 11:46
 * @description https://www.lanqiao.cn/problems/19784/learning/?page=1&first_category_id=1
 */
public class Main {
    /**
     * 思路；计数, 从大的开始去人,
     * 先是每一个去一个人
     * 发现不够, 那就去重复的多的
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] num = new int[N];
    static int n, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        k = sc.nextInt();
        while (n-- > 0) {
            int x = sc.nextInt();
            num[x]++;
        }
        Arrays.sort(num, 1, N);
        for (int i = 1, j = N - 1; i < j; i++, j--) {
            int tmp = num[i];
            num[i] = num[j];
            num[j] = tmp;
        }
        int res = 0;
        // 每一个城区去一个人
        for (int i = 1; ; i++) {
            if (num[i] == 0) break;
            res ++;
            k--;
            num[i]--;
            if (k == 0) break;
        }
        // 发现不够, 那就去重复的多的
        for (int i = 1; num[i] > 0 && k > 0; i++) {
            res --;
            k -= num[i];
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

